/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.agent.dao;

import java.util.Date;
import java.util.Map;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import ru.ffind.agent.db.DbDirectory;
import ru.ffind.common.model.Filename;

/**
 * Implementation for creating new files in batch.
 *
 * @author Rage Steel
 */
public class InsertFileBatchImpl extends AbstractBatch implements InsertFileBatch {

    private final SimpleJdbcInsert simpleJdbcInsertFile;

    private final Date appDate;

    public InsertFileBatchImpl(SimpleJdbcInsert simpleJdbcInsertFile,
            Date appDate) {
        this.simpleJdbcInsertFile = simpleJdbcInsertFile;
        this.appDate = appDate;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void insertFilename(DbDirectory parentDir, Filename base) {
        fileArgs.add(
                ArgUtils.createFilenameArgs(parentDir, base, appDate));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void doExecute(Map<String, Object>[] batch) {
        simpleJdbcInsertFile.executeBatch(batch);
    }
}
